$(function() { $("#tabs").tabs();  });
  
$(document).ready(function() { 
    
    hs.graphicsDir = url_base+'app/admin/view/temp/default/layout/css/highslide/graphics/';
    hs.align = 'center';
    hs.closeText = '<img border="0" src="'+url_base+'app/admin/view/temp/default/layout/css/highslide/graphics/close_X.png" />';
    hs.creditsText = 'this.a.title';
    hs.outlineType = 'rounded-white';
    hs.showCredits = false;
    hs.wrapperClassName = 'draggable-header';
    hs.cacheAjax = false;
    hs.dimmingOpacity = 0.7;
    hs.onDimmerClick = function() { return false;}
    
     
    $('#btn-submit').click(function() {  
    
      var hasError = false;
      var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    
      var emailaddressVal = $("#Email").val();
      if(emailaddressVal == '') {
          $(".error").show().text(_['error_emal_empty']);
          hasError = true;
      }
    
      else if(!emailReg.test(emailaddressVal)) {
          $(".error").show().text(_['error_emal_no_format']);
          hasError = true;
      }
    
      if(hasError == true) { return false; }
    
    });
    
    $('input:checkbox[name="delId[]"]').click(function() { 
    
    if( $(this).attr("checked")== "checked"){
        
        $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
        
    }else{
        
        if(getValCb().length>0)
        {               
            $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
        }else{
            $('.but_tool').removeClass('but_login').addClass('butx').attr("disabled",true);   
        }
        
        
    }
    
    
    
    });
    
    /********validate form********/    
    $("#frm_editor").validate({
        errorPlacement: function(error, element) {
        element.parent().addClass('error_label');
        },
        submitHandler: function() {
            if(validate_select()){
                form.submit();
            }else{
                return false;           
            }
            
        }
	});



    $.validator.addMethod("NumbersOnly", function(value, element) {
        if(value == ''){
            return true;
        }else{
            return this.optional(element) || /^[0-9\-\+]+$/i.test(value);
        }
        
    }, "");

 });
function checkAll()
{
    if(getValCb().length>0){
        
        $('.but_tool').removeClass('but_login').addClass('butx').attr("disabled",true);
        $('input:checkbox[name="all"]').removeAttr("checked");
		$('input:checkbox[name="delId[]"]').removeAttr("checked");
        
	}else{
	    
        $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
	    $('input:checkbox[name="all"]').attr("checked","checked");
		$('input:checkbox[name="delId[]"]').attr("checked","checked");
    }
	
}

function getValCb()
{
	var delId = [];
	$('input:checkbox[name="delId[]"]:checked')
	.each( function(index) { 
		delId.push($(this).val());
	});
	
	return delId;
}

function processChecked(active, com)
{
    var StrID = getValCb();
	switch (active)
	{
		case 'show':
			var strData = _seokey[0]+'/'+com+"/ajax/"+active+"/"+StrID;
			var sms = _['showx'];
			var smsError=_['error_show'];
			var errorNotOK = _['error_ok_show'];
            var status = _['show'];
            var classx = 're';
        break;
		
		case 'hide':
			var strData = _seokey[0]+'/'+com+"/ajax/"+active+"/"+StrID;
			var sms =  _['hidex'];
			var smsError=_['error_hide'];
			var errorNotOK = _['error_ok_hide'];
            var status = _['hide'];
            var classx = 'add';
        break;
        
        case 'delete':
			var strData = _seokey[0]+'/'+com+"/ajax/"+active+"/"+StrID;
			var sms =  _['delete'];
			var smsError=_['error_delete'];
			var errorNotOK = _['error_ok_delete'];
            var deletex = 'ok';
		break;
        
	}
	
	if(StrID!=""){
		var smsCheck = confirm(sms);
		if(smsCheck==true){
			$.ajax({ 
			   type: "POST", 
			   url: url_base+""+strData, 
			   cache: false,
			   dataType: "html",
			   success: function(DataHtml){ 
			   	 if(DataHtml=='ok')
                 {
				 	for(x in StrID)
                    {
                        if(deletex)
                        {
                            $('.tr'+StrID[x]).remove();                                
                        }
                        else{
                         
                            $('.status'+StrID[x]).text(status);
                            if(classx=='add'){
                                $('.tr'+StrID[x]).addClass('class_false');
                                $('.tr'+StrID[x]).removeClass('class_true');
                            }else{
                                $('.tr'+StrID[x]).removeClass('class_false');
                                $('.tr'+StrID[x]).addClass('class_true');
                            }
                            
                        }
                        
                    }
                    if(active == 'delete'){
                        location.reload(true);    
                    }
                    
				 }
                 else{
                    alert(errorNotOK);                   
                    
				 }
				 
			   } 
			});
		}
	
	}else{
		alert(smsError);
	
	}
}